package com.weixin.sdk.pay;

import java.lang.reflect.Field;
import java.util.TreeMap;

import org.apache.commons.lang3.ArrayUtils;

import com.weixin.sdk.utils.SignKit;

public abstract class BaseReqCommData implements BaseReq{
	private static final long serialVersionUID = 1L;
	  protected String sign;
	  protected String nonce_str;
	  protected String mch_sec_key;
	  
	  public BaseReqCommData()
	  {
	    setNonce_str(SignKit.genRandomString32());
	  }
	  
	  public TreeMap<String, Object> toMap()
	  {
	    TreeMap<String, Object> map = new TreeMap();
	    Field[] superFields = getClass().getSuperclass().getDeclaredFields();
	    Field[] fields = getClass().getDeclaredFields();
	    Field[] allFields = (Field[])ArrayUtils.addAll(superFields, fields);
	    
	    Field[] superFieldss = getClass().getSuperclass().getSuperclass().getDeclaredFields();
	    if (superFieldss != null) {
	      allFields = (Field[])ArrayUtils.addAll(superFieldss, allFields);
	    }
	    Field[] arrayOfField1;
	    int j = (arrayOfField1 = allFields).length;
	    for (int i = 0; i < j; i++)
	    {
	      Field field = arrayOfField1[i];
	      field.setAccessible(true);
	      try
	      {
	        Object obj = field.get(this);
	        if ((obj != null) && 
	          (!"serialVersionUID".equals(field.getName())) && (!"mch_sec_key".equals(field.getName()))) {
	          map.put(field.getName(), obj);
	        }
	      }
	      catch (IllegalArgumentException e)
	      {
	        e.printStackTrace();
	      }
	      catch (IllegalAccessException e)
	      {
	        e.printStackTrace();
	      }
	    }
	    return map;
	  }
	  
	  public String getSign()
	  {
	    return this.sign;
	  }
	  
	  public void setSign(String sign)
	  {
	    this.sign = sign;
	  }
	  
	  public String getNonce_str()
	  {
	    return this.nonce_str;
	  }
	  
	  public void setNonce_str(String nonce_str)
	  {
	    this.nonce_str = nonce_str;
	  }
	  
	  public String getMch_sec_key()
	  {
	    return this.mch_sec_key;
	  }
	  
	  public void setMch_sec_key(String mch_sec_key)
	  {
	    this.mch_sec_key = mch_sec_key;
	  }

}
